package com.cskaoyan.service.wx.impl;

import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.po.MarketFootprint;
import com.cskaoyan.bean.po.MarketUser;
import com.cskaoyan.bean.vo.wx.WxFootprintVo;
import com.cskaoyan.mapper.MarketFootprintMapper;
import com.cskaoyan.service.wx.WxFootprintService;
import com.cskaoyan.util.GetInfo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author jzp
 * @since 2022/11/22 20:28
 */
@Service
public class WxFootprintServiceImpl implements WxFootprintService {
    @Autowired
    MarketFootprintMapper marketFootprintMapper;

    @Override
    public CommonData list(Integer page, Integer limit) {
        MarketUser wxLoginInfo = GetInfo.getWxLoginInfo();
        Integer userId = wxLoginInfo.getId();
        PageHelper.startPage(page, limit);
        List<WxFootprintVo> wxFootprintVoList = marketFootprintMapper.selectFootInfo(userId);
        PageInfo<WxFootprintVo> pageInfo = new PageInfo<>(wxFootprintVoList);
        return CommonData.data(pageInfo);
    }

    @Override
    @Transactional
    public int delete(Integer id) {
        MarketFootprint marketFootprint = new MarketFootprint();
        marketFootprint.setId(id);
        marketFootprint.setDeleted(true);
        return marketFootprintMapper.updateByPrimaryKeySelective(marketFootprint);
    }
}
